#!/bin/sh

. ../../func
. ../../build.conf

if [ -f /usr/lib/pkgconfig/libudev.pc ] ; then
	udevver=$(grep 'Version: ' /usr/lib/pkgconfig/libudev.pc  | cut -f 2 -d ' ')
elif [ -f /usr/lib64/pkgconfig/libudev.pc ] ; then
	udevver=$(grep 'Version: ' /usr/lib64/pkgconfig/libudev.pc  | cut -f 2 -d ' ')
elif [ -f /usr/share/pkgconfig/udev.pc ] ; then
	udevver=$(grep 'Version: ' /usr/share/pkgconfig/udev.pc  | cut -f 2 -d ' ')
fi
echo $udevver
if [ "$udevver" != "" -a $udevver -lt 200 ] ; then
	echo "Not compiling eudev..."
	sleep 3
	exit
fi

URL=https://github.com/gentoo/eudev/archive
PKG=eudev
VER=3.2.5
COMP=tar.gz
DESC="programs for dynamic creation of device nodes."
DEPS=
CAT=BuildingBlock
DESKTOP=eudev.desktop
BUILD=
CWD=$(pwd)
[ -z "$BUILD" ] && BUILD=$DEF_BUILD
# comment these 2 below if you use a custom package() function
[ -f "$DESKTOP" ] || DESKTOP=not
[ -z "$DEPS" ] && DEPS=not

ARCH=$(uname -m)
case $ARCH in # set in build.conf
 *64) 	LIBDIR=$LIBCONF64 
		FLAGS=$CF64;;
 arm*)	LIBDIR=$LIBCONFarm
		FLAGS="-O2" ;;
 i686) 	LIBDIR=$LIBCONF32 
		FLAGS=$CF32;;
	*) 	LIBDIR=$LIBCONF32 
		FLAGS="-O2 -march=$ARCH -mtune=$ARCH";;
esac
#---

prepare() {
	sed -e 's/GROUP="dialout"/GROUP="uucp"/' -i rules/*.rules
}

build() {
	./autogen.sh
	CFLAGS="${FLAGS}" \
	CXXFLAGS="${FLAGS}" \
	./configure \
		--prefix=/usr \
		--bindir=/bin \
		--with-rootprefix=/usr \
		--sysconfdir=/etc \
		--libdir=/lib \
		--sbindir=/sbin \
		--disable-static \
		--disable-introspection \
		--enable-kmod
}

package() {
	make
	make DESTDIR="${pkgdir}" install
	make -C src/libudev DESTDIR="$pkgdir" install
	make -C rule_generator DESTDIR="$pkgdir" install
}

#====================================================

retrieve v${VER}.${COMP}
extract v${VER}.${COMP}

#--
#build_configure $PKG $VER $LIBDIR "$FLAGS"
	cd ${PKG}-${VER}
	prepare
	build
	[ "$?" -eq 0 ] || exit
	make $MKFLG
	[ "$?" -eq 0 ] || exit
	make install
	make DESTDIR=$CWD/${PKG}-install install
	cd -
#--

#fix pkgconfig location
mkdir -p ${PKG}-install/usr/lib
mv -f ${PKG}-install/lib/pkgconfig ${PKG}-install/usr/lib

package_std $PKG $VER $ARCH $DESKTOP "$DESC" $DEPS $CAT

### END ##
